#ifndef __DIRECTOR_H__
#define __DIRECTOR_H__

#include "stdafx.h"
#include "Singleton.h"
#include "Input.h"
#include "Scene.h"
#include <map>

using namespace std;

namespace GeorgeLib
{


	///	@brief
	///	Creates and handles the main OpenGL window, and manages @link Scene Scenes @endlink

	/**	@details
		The Director is responsible for:
		- initializing the OpenGL context
		- initializing the OpenGL Extensions Wrapper (GLEW)
		**/

	class DLLEXPORT Director : public Singleton < Director >
	{

		/*		How to use this class		*/
		// Director* dir = Director::getInstance();
		// dir->Init(argc,argv);
		// dir->AddScene("myScene", new myScene, true);

	private:

		Scene *currentScene, *previousScene;

		typedef map<string, Scene*> SceneMap;
		typedef SceneMap::iterator SceneMapIter;
		SceneMap scenes;

		float	fps,
			deltaTime;

	public:

		/// Constructor
		Director(void);

		/// Destructor
		~Director(void);

		Input *input;	// Pointer to the input interface

		// Simple one-liner to initialise your OpenGL program
		void		Init(int argc, char ** argv, const char* title,
			int width = 800, int height = 600);

		// Resize your window
		void		SetWindowSize(int width, int height);

		// Start the OpenGL main lopp
		void		Start(void) { glutMainLoop(); };

		// Add a Scene to the list, with the option of running the newly added scene
		void		AddScene(string name, Scene * scene, bool bRunScene = false);

		// Change the Scene
		void		ChangeScene(string name);

		Scene*		getScene(string name) { return scenes[name]; };

		Scene*		getCurrScene(void) { return currentScene; }

		Scene*		getPrevScene(void) { return previousScene; }

		float		getFPS(void) { return fps; }

		float		getDeltaTime(void) { return deltaTime; }

	private:

		/* SCENE FUNCTIONS */

		// Render and Update function
		friend	void	SceneDisplay(void);

		// Function to check for keys that are pressed
		friend	void	SceneKeyboardDown(unsigned char key, int x, int y);

		// Function to check for keys that are released
		friend	void	SceneKeyboardUp(unsigned char key, int x, int y);

		// Function to check for special keys that are pressed
		friend	void	SceneSpecialDown(int key, int x, int y);

		// Function to check for special keys that are released
		friend	void	SceneSpecialUp(int key, int x, int y);

		// Function to check for button press
		friend	void	SceneMouse(int button, int state, int x, int y);

		// Function to check for mouse movement when the buttons are pressed
		friend	void	SceneMotion(int x, int y);

		// Function to check for mouse movement when the buttons are not pressed
		friend	void	ScenePassiveMotion(int x, int y);

		int FPStimer, currTime, prevTime; // timers for FPS
		int framecount; // counter for fps
		void calcFPS(void);
	};

} // namespace GeorgeLib

#endif // __DIRECTOR_H__ //